#! /usr/bin/python3
# -*- coding: UTF-8 -*-
  
'''※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※
File Name: datas.py
Author: GID5564
Description: 
Version: 1.0
Created Time: 03/10/24-16:38:23
※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※'''

__all__ = ['get_solar_term', 'get_weekday', 'get_constellation']

from datetime import datetime
from enum import Enum


def get_solar_term(date_str):
    """
    根据给定日期，返回节气名
    :param date_str: 日期，格式为 "YYYY-MM-DD"
    :return: 节气名
    """
    # 二十四节气与公历大概对应日期
    solar_terms = [
        "小寒", "大寒", "立春", "雨水", "惊蛰", "春分", "清明", "谷雨",
        "立夏", "小满", "芒种", "夏至", "小暑", "大暑", "立秋", "处暑",
        "白露", "秋分", "寒露", "霜降", "立冬", "小雪", "大雪", "冬至"
    ]
    date_obj = datetime.strptime(date_str, '%Y-%m-%d')
    # 计算给定日期是一年中的第几天
    day_of_year = date_obj.timetuple().tm_yday
    # 用一年365天的比例计算节气索引
    term_index = (day_of_year - 1) % 24
    return solar_terms[term_index]

class Weekday(Enum):
    MONDAY = "星期一"
    TUESDAY = "星期二"
    WEDNESDAY = "星期三"
    THURSDAY = "星期四"
    FRIDAY = "星期五"
    SATURDAY = "星期六"
    SUNDAY = "星期日"

def get_weekday(date_str: str) -> (str, str):
    """
    根据给定日期，返回该星期几。

    参数：
        date_str (str): 日期字符串，格式为 "YYYY-MM-DD"。

    返回：
        tuple: (zn, en)
        星期几的字符串表示，如 "Monday", "Tuesday" 等。
    """

    # 将输入的字符串转换为 datetime 对象
    date_obj = datetime.strptime(date_str, '%Y-%m-%d')

    # 获取星期几的整数表示（0-6，0 表示星期一）
    weekday_num = date_obj.weekday()

    # 将整数转换为对应的星期几字符串
    weekdays = {
        0: (Weekday.MONDAY.value, "Monday"),
        1: (Weekday.TUESDAY.value, "Tuesday"),
        2: (Weekday.WEDNESDAY.value, "Wednesday"),
        3: (Weekday.THURSDAY.value, "Thursday"),
        4: (Weekday.FRIDAY.value, "Friday"),
        5: (Weekday.SATURDAY.value, "Saturday"),
        6: (Weekday.SUNDAY.value, "Sunday")
    }

    return weekdays[weekday_num]



def get_constellation(month, day) -> (str, str):
    """
    根据日期，获取对应的星座
    :param month: 月份
    :param day: 几号
    :return: 星座中文名，星座英文名
    """
    days = (21, 20, 21, 21, 22, 22, 23, 24, 24, 24, 23, 22)
    constellations = ("摩羯座", "水瓶座", "双鱼座", "白羊座", "金牛座", "双子座", "巨蟹座", "狮子座", "处女座", "天秤座", "天蝎座", "射手座")
    dict_ = {"水瓶座": "Aquarius",
             "双鱼座": "Pisces",
             "白羊座": "Aries",
             "金牛座": "Taurus",
             "双子座": "Gemini",
             "巨蟹座": "Cancer",
             "狮子座": "Leo",
             "处女座": "Virgo",
             "天秤座": "Libra",
             "天蝎座": "Scorpio",
             "射手座": "Sagittarius",
             "摩羯座": "Capricorn"}

    if day < days[month - 1]:
        cons_name = constellations[month - 1]
    else:
        cons_name = constellations[month]
    return cons_name, dict_[cons_name]























